import unittest
from common.open_browser import open_browser
from page.login_page import LoginPage
from page.receiving_address_curd_page import Curd
import time
from common.base import By


class ReceivingCurdTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver = open_browser()
        driver.maximize_window()
        # 创建LoginPage和Curd对象
        cls.login = LoginPage(driver)
        cls.curd = Curd(driver)

    def test1_add(self):
        # 打开浏览器
        self.login.get('http://172.16.140.48/ecshop/user.php')
        # self.login.implicitly_wait(10)
        # 输入登录信息
        self.login.input_username('wlyou')
        self.login.input_password('123456')
        self.login.input_remember()
        self.login.input_submit()
        # 点击用户中心
        time.sleep(2)
        self.curd.click((By.LINK_TEXT, '用户中心'))
        # 点击收货地址
        time.sleep(2)
        self.curd.click((By.XPATH, '/html/body/div[6]/div[1]/div/div/div/div/a[4]'))
        # 收货地址操作
        # 配送区域
        # time.sleep(2)
        self.curd.input_country('中国')
        time.sleep(2)
        self.curd.input_province('湖北省')
        time.sleep(2)
        self.curd.input_city('武汉市')
        time.sleep(2)
        self.curd.input_district('江夏区')
        # 收货人
        time.sleep(2)
        self.curd.input_consignee('wl')
        # 电子邮件地址
        time.sleep(2)
        self.curd.input_email('123456@123.com')
        # 收货地址
        time.sleep(2)
        self.curd.input_address('源码时代')
        # 电话号码
        time.sleep(2)
        self.curd.input_phone('17671765961')
        # 点击新增收货地址按键
        self.curd.input_submit()

    def test2_alter(self):
        # 修改收获地址和电话号码
        time.sleep(5)
        self.curd.a_input_address('光谷广场')
        time.sleep(2)
        self.curd.a_input_phone('15871952310')
        time.sleep(2)
        self.curd.input_confirm_modification()

    def test3_delete(self):
        # 删除收货地址
        time.sleep(5)
        self.curd.input_delete()
        self.curd.input_alert()

    @classmethod
    def tearDownClass(cls) -> None:
        # 后大夹具,退出浏览器
        time.sleep(5)
        cls.login.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
